package xyz.sicau.test1;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import xyz.sicau.utils.MQUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

public class Consumer {
    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = MQUtils.getChannel();

        DeliverCallback deliverCallback = (consumerTag, message) -> {
//            MQUtils.sleep(1);
            System.out.println("接收消息: " + new String(message.getBody(), StandardCharsets.UTF_8));
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };

        CancelCallback cancelCallback = (s) -> {
            System.out.println("取消消息: " + s);
        };
        channel.basicQos(10);

        channel.basicConsume(QUEUE_NAME, false, deliverCallback, cancelCallback);
    }


}
